;(function($){  
	$.Service=function(){
		var methods;
		methods={
			help:function(){
				var wrp,sp,bk,menus,items,menu,con;
				wrp=$('#helpwrp');
				sp=$('.place span',wrp);
				bk=$('.place .back',wrp);
				menus=$('.helpmenu a',wrp);
				items=$('.item',wrp);
				menu=$('.helpmenu',wrp);
				con=$('.helpcon',wrp);
				menus.each(function(i,n){
					$(n).click(function(e){
						e.preventDefault();
						var name=$(this).html().replace(/？/g,'');
						sp.html(name);
						menu.hide();
						con.show();
						items.hide();
						$(items[i]).show();
						bk.show();
						$.ImgLazy(items[i]);
					});
				});
				$('.back',wrp).click(function(){
					menu.show();
					con.hide();
					sp.html('列表');
					bk.hide();
				});
			},
			loadertest:function(){
				var self,wrp,lder,ldtx,bef,end;
				self=this;
				self.loadfst=new Date();
				if(self.loaderTimer){
					clearTimeout(self.loaderTimer);
				}
				self.loadstate=0;
				wrp=$('#report');
			    lder=$('.testload i',wrp);
				ldtx=$('.testloadrs',wrp);
				lder.width('0%');
				ldtx.html('自动测试中...');
				bef=function(mtime,f){
					f=f||false;
					self.loaderTimer=setTimeout(function(){
					     self.loadstate++;
					     lder.width(self.loadstate+'%');
						 if(self.loadstate >= 100){
							 clearTimeout(self.loaderTimer);
							 if(f){
								 f();
							 }
						 }else{
						     bef(mtime,f);
						 }
				    },mtime);
				};
				end=function(f){
					var least,mtime;
					least=100-self.loadstate;
					if(least <=0 ){
						return ;
					}
					mtime=Math.floor(1000/least);
					bef(mtime,f);
				};
				$('<img src="'+_glb.baseurl+'/ui/img/tester.jpg?'+self.loadfst.getTime()+'"/>').bind('load',function(){
					var fs,l,alltime,num,speed,speed2,level;
				    fs = 0.984*1024;  
					l = 2; 
					alltime = fs*1000/(new Date() - self.loadfst);
					num = Math.pow(10,l);
					speed = Math.round(alltime*num)/num;
					speed2 = parseInt(speed);
					if(speed2<100){
						level = "较慢";
					}else if(speed2<500){
						level = "正常";
					}else{
						level = "较快";
					}
					self.loadspeed = speed;
					if(self.loaderTimer){
					   clearTimeout(self.loaderTimer);
				    }
					end(function(){
						ldtx.html('测试完成，您当前连接到3wmm.com网站的网速为：<b>'+speed+'KB/秒[网速'+level+']</b>，请填写反馈内容后提交');
					});
				}).bind('error',function(){
					if(self.loaderTimer){
					   clearTimeout(self.loaderTimer);
				    }
					self.loadspeed = 0;
					lder.width('0%');
					var s=$('<span>测试失败，点这里<b style="cursor:pointer;">重新测试</b></span>');
					s.find('b').click(function(){
						self.loadertest();
					});
					ldtx.html('').append(s);
				});
				bef(300);
			},
			report:function(){
				var self,wrp,x;
				self=this;
				self.loadspeed = 0;
				self.loadertest();
				wrp=$('#report');
				x=navigator;
				self.ua=x.userAgent;
				$('.browserua',wrp).html(self.ua);
				self.browser=x.appVersion + "\n" + self.ua;
				$('.resub',wrp).click(function(){
					var data={};
					data.tn = 'report';
					data.url = wrp.attr('rel');
					data.speed = self.loadspeed;
					data.browser = self.browser;
					data.type = $("input[name='msgtype']:checked",wrp).val();
					data.msg = $.trim($("textarea[name='msg']").val());
					data.contact = $.trim($("input[name='contact']").val());
					if(data.msg==''){
						alert('请填写一下问题描述吧！');
						$("textarea[name='msg']").focus();
						return ;
					}
					if(data.contact==''){
						alert('请留下您的联系信息吧！');
						$("input[name='contact']").focus();
						return ;
					}
					$.post(_glb.baseurl+'/i/7323.php',data,function(dat){
						alert('信息已经提交！感谢您的反馈');
						location.href=_glb.baseurl;
					});
				});
			},
		    
			init:function(pflash,cfg){
				var self,fid;
				self=this;
				fid=$('body').attr('fid')||'';
				if(fid=='help'){
					self.help();
				}else if(fid=='report'){
					self.report();
				}
				
				return self;
			}
		};
		return methods.init();
	}
})(jQuery);



